<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加/编辑指标</title>
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>


<body>


<fieldset class="layui-elem-field layui-field-title"
          style="margin-top: 50px;">
    <legend>选项编辑</legend>
</fieldset>
<form  class="layui-form layui-form-pane" >

    <input type="hidden" name="optionId"  >

    <input type="hidden" name="indexId"  >


    <div class="layui-form-item">
        <label class="layui-form-label">指标id</label>
        <div class="layui-input-inline">
            <input id="indexId" name="indexId" lay-verify="required" placeholder="请选择指标"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选项内容</label>
        <div class="layui-input-inline">
            <input name="description" lay-verify="required" placeholder="请输入选项内容"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选项分值</label>
        <div class="layui-input-inline">
            <input name="optionScore" lay-verify="required" placeholder="请输入选项分值"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>



    <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="form1" >提交</button>
    </div>

</form>

<script src="layui/layui.js"></script>
<script src="layui/layui.all.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
<script src="layui/lay/modules/tableSelect.js"></script>

<script type="text/javascript">

    var tableSelect = layui.tableSelect;

    /** 监听部门编号input框 */
    tableSelect.render({
        elem: '#indexId',
        searchKey: 'indexName',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '指标名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/index/list',
            cols: [[
                { type: 'radio' },
                { field: 'indexId', title: '结点' },
                { field: 'indexName', title: '指标名' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.indexId)
            })
            elem.val(NEWJSON.join(","))
        }
    });
</script>




<script type="text/javascript">
    layui.use(["form", "layer", "jquery"], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        /* function parseUrl(){
             var url=location.href;
             var i=url.indexOf('?');
             if(i==-1)return;
             var querystr=url.substr(i+1);
             var arr1=querystr.split('&');
             var arr2=new Object();
             for  (i in arr1){
                 var ta=arr1[i].split('=');
                 arr2[ta[0]]=ta[1];
             }
             return arr2;
         }
         var v = parseUrl();//解析所有参数
         // alert(v['userId']);//就是你要的结果
         var */

        var Ohref=window.location.href;
        var arrhref=Ohref.split("?optionId=");
        // alert(arrhref[1]);
        var optionId = arrhref[1];


        (function(){
            if (optionId !== undefined) {         //判断我是点的添加还是编辑
                /*此处是在编辑的时候根据userId在后台查询用户的全部信息并数据回显*/
                $.ajax({
                    url:"/evaluation/option/findOptionByOptionId",
                    type:"get",
                    data:{optionId:optionId},
                    dataType:"json",
                    success:function(data){
                        var option = data.data;

                        // $("#userInfo").text(username + "    " + userNo);
                        // window.location.href ="login.html";
                        $("input[name='optionId']").val(option.optionId);
                        $("input[name='description']").val(option.description);
                        $("input[name='optionScore']").val(option.optionScore);
                        $("input[name='indexId']").val(option.indexId);

                    },
                    error:function(xmlHttpRequest,textStatus,errorThrown){
                        alert(textStatus+"出错！"+errorThrown);
                    }
                });
            }
        })();







        form.on("submit(form1)", function (data) {
            /* layer.alert(($("#userId").val()==null || $("#userId").val()=='') ? "添加成功!" : "修改成功!", {icon: 1}); */
            $.post("/evaluation/option/save", data.field,function(d){
                if (d.code === 15 || d.code === 16){
                    layer.msg("很抱歉！操作失败了。",{icon: 5,time: 1500},function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }else if (d.code === 0) {
                    layer.msg("恭喜您！操作成功了。",{icon: 6,time: 1500},function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }
            },"json");




            return false;
        });



    });
</script>

</body>
</html>